﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 药品信息管理
{
    public partial class YP_XHPM : Form
    {
        public YP_XHPM()
        {
            InitializeComponent();
        }

        private void YP_XHPM_Load(object sender, EventArgs e)
        {
            numericUpDown1.Value = 10;
            dateTimePicker1.Value = DateTime.Now.AddDays(-(DateTime.Now.Day - 1));
            radioButton1_CheckedChanged(sender, e);
         
        }

        private void buttonItem1_Click(object sender, EventArgs e)
        {
            db db1 = new db();
            string time1 = dateTimePicker1.Value.ToString("yyyy.MM.dd"), time2 = dateTimePicker2.Value.ToString("yyyy.MM.dd");
            int r = Convert.ToInt32(numericUpDown1.Value.ToString());
            string str = @"SELECT top "+r+ @" SUM(D1.JE) a, NR.BM 编码, NR.MC 名称, NR.GG 规格, NR.BZDW 单位, SUM(D1.SL) 数量, SUM(D1.JE) 金额
                                 FROM YK_CKD0 D0, YK_CKD1 D1, ZD_YP NR 
                                 WHERE D0.CKDH=D1.CKDH AND  NR.BM=D1.YPBM 
                                 AND D0.RQ >= " + db1.datetoint(time1) + " AND D0.RQ<= " + db1.datetoint(time2) + " GROUP BY NR.BM, NR.MC, NR.GG, NR.BZDW;";
            dataGridViewX1.DataSource = db1.sqldt(str);
            dataGridViewX1.Columns["a"].Visible = false;
        }


        private void textBoxX1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            db db1 = new db();

            string time1 = dateTimePicker1.Value.ToString("yyyy.MM.dd"), time2 = dateTimePicker2.Value.ToString("yyyy.MM.dd");
            int r = Convert.ToInt32(numericUpDown1.Value.ToString());
            string str = @"SELECT top " + r + @" SUM(D1.JE) a, NR.BM 编码, NR.MC 名称, NR.GG 规格, NR.BZDW 单位, SUM(D1.SL) 数量, SUM(D1.JE) 金额
                                 FROM YK_CKD0 D0, YK_CKD1 D1, ZD_YP NR 
                                 WHERE D0.CKDH=D1.CKDH AND  NR.BM=D1.YPBM 
                                 AND D0.RQ >= " + db1.datetoint(time1) + " AND D0.RQ<= " + db1.datetoint(time2) + " GROUP BY NR.BM, NR.MC, NR.GG, NR.BZDW ORDER BY A DESC;";
            dataGridViewX1.DataSource = db1.sqldt(str);
            dataGridViewX1.Columns["a"].Visible = false;
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            db db1 = new db();
            string time1 = dateTimePicker1.Value.ToString("yyyy.MM.dd"), time2 = dateTimePicker2.Value.ToString("yyyy.MM.dd");
            int r = Convert.ToInt32(numericUpDown1.Value.ToString());

            string str = @"SELECT top " + r + @"  SUM(D1.SL) a, NR.BM 编码, NR.MC 名称, NR.GG 规格, NR.BZDW 单位, SUM(D1.SL) 数量, SUM(D1.JE) 金额
                                 FROM YK_CKD0 D0, YK_CKD1 D1, ZD_YP NR 
                                 WHERE D0.CKDH=D1.CKDH AND  NR.BM=D1.YPBM 
                                 AND D0.RQ >= " + db1.datetoint(time1) + " AND D0.RQ<= " + db1.datetoint(time2) + " GROUP BY NR.BM, NR.MC, NR.GG, NR.BZDW ORDER BY A DESC;";
            dataGridViewX1.DataSource = db1.sqldt(str);
            dataGridViewX1.Columns["a"].Visible = false;
        }

        private void textBoxX1_TextChanged_1(object sender, EventArgs e)
        {
            foreach (DataGridViewRow R1 in dataGridViewX1.Rows)
            {
                if (R1.Cells["编码"].Value.ToString() == textBoxX1.Text)
                {
                    R1.Selected = true;
                }
                else { R1.Selected = false; }
            }

        }
    }
}